<?php 
/**
 * 知识星球控制器
 */
class Lore extends Admin_Controller
{
	
	function __construct(){
		parent::__construct();

		$this->load->model('Admin/Lore_model', 'lore');
	}

	/**
	 * [知识列表]
	 * @Author   zt
	 * @DateTime 2018-08-03
	 * @param    integer    $page [页码]
	 */
	function loreList($page = 1)
	{
		$data = $this->lore->loreList($page);

		$data['page'] = $page;	// 当前页码
		$data['start'] = ($page - 1) * LINES + 1;	// 当前页起始条数

		// 当前页截止条数
		if ($page * LINES >= $data['count']) {
			$data['end'] = $data['count'];
		} else {
			$data['end'] = $page * LINES;
		}
		
		// 获取筛选条件
		$data['get'] = $_SERVER['QUERY_STRING'];

		// 每页显示条数
		$data['line'] = LINES;

		// 页面跳转链接
		$data['url'] = base_url().'Admin/Lore/loreList/';
		$this->load->view('Admin/Lore/LoreList', $data);
	}

	/**
	 * [知识添加]
	 * @Author   zt
	 * @DateTime 2018-08-03
	 * @return   [type]     [description]
	 */
	function loreAdd()
	{
		if ($_POST) {
			$post = $this->input->post();
			$post = Common::_clean($post);
			$res = $this->lore->loreAdd($post);
			if ($res['code'] == 1) {
				$this->success($res['msg'], base_url().'Admin/Lore/loreList');
			} else {
				$this->error($res['msg']);
			}
		} else {
			$this->load->view('Admin/Lore/LoreAdd');
		}
	}

	/**
	 * [知识编辑]
	 * @Author   zt
	 * @DateTime 2018-08-03
	 * @param    [type]     $id [知识id]
	 * @return   [type]         [description]
	 */
	function loreUpdate($id)
	{
		if ($_POST) {
			$post = $this->input->post();
			$post = Common::_clean($post);
			$res = $this->lore->loreUpdate($id, $post);
			if ($res['code'] == 1) {
				$this->success($res['msg'], base_url().'Admin/Lore/loreList');
			} else {
				$this->error($res['msg']);
			}
		} else {
			$data = $this->lore->loreFind($id);
			$this->load->view('Admin/Lore/LoreAdd', $data);
		}
	}

	/**
	 * [知识上架下架]
	 * @Author   zt
	 * @DateTime 2018-08-03
	 * @param    [type]     $id   [知识id]
	 * @param    [type]     $type [1上架2下架]
	 */
	function loreRelease($id, $type)
	{
		$res = $this->lore->loreRelease($id, $type);
		if ($res['code'] == 1) {
			$this->success($res['msg']);
		} else {
			$this->error($res['msg']);
		}
	}
}